package com.gitee.mars.vaccin.controller;

import com.gitee.mars.vaccin.entity.SysRoleMenu;
import com.gitee.mars.vaccin.response.base.BasePageRequest;
import com.gitee.mars.vaccin.response.base.PageInfo;
import com.gitee.mars.vaccin.response.result.R;
import com.gitee.mars.vaccin.service.SysRoleMenuService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * 控制层
 *
 * @Author wq
 * @Date 2020-12-15
 **/
@RestController
@RequestMapping("admin/sysRoleMenu")
@AllArgsConstructor
public class SysRoleMenuController {

    private final SysRoleMenuService sysRoleMenuService;

    /**
     * 新增
     *
     * @param sysRoleMenu sysRoleMenu
     */
    @PostMapping("/add")
    public void add(@RequestBody SysRoleMenu sysRoleMenu) {
        sysRoleMenuService.save(sysRoleMenu);
    }

    /**
     * 删除
     *
     * @param ids ids
     */
    @GetMapping("/delete")
    public void delete(@RequestParam("ids") Long... ids) {
        sysRoleMenuService.removeByIds(Arrays.asList(ids));
    }

    /**
     * 更新
     *
     * @param sysRoleMenu sysRoleMenu
     */
    @PostMapping("/update")
    public void update(@RequestBody SysRoleMenu sysRoleMenu) {
        sysRoleMenuService.updateById(sysRoleMenu);
    }

    /**
     * 详情
     *
     * @param id id
     * @return SysRoleMenu
     */
    @GetMapping("/detail")
    public SysRoleMenu detail(@RequestParam("id") Long id) {
        return sysRoleMenuService.getById(id);
    }

    /**
     * 分页
     *
     * @param query query
     * @return IPage<SysRoleMenu>
     */
    @PostMapping("/page")
    public R userList(@RequestBody(required = false) BasePageRequest query) {
        return R.success(PageInfo.buildPage(sysRoleMenuService.page(query)));
    }

}